"""
系统访问日志模型
包含:
1. AccessLogModel - 访问日志
"""

from tortoise import fields

from app.models.base_model import BaseModel


class AccessLogModel(BaseModel):
    """访问日志模型"""

    id = fields.IntField(pk=True)
    request_id = fields.CharField(max_length=255, description="请求ID", null=True)
    path = fields.CharField(max_length=255, description="访问路径")
    method = fields.CharField(max_length=10, description="请求方法")
    ip = fields.CharField(max_length=50, description="IP地址")
    user_agent = fields.CharField(max_length=255, null=True, description="User Agent")
    status_code = fields.IntField(description="状态码")
    request_body = fields.JSONField(null=True, description="请求体")
    response_body = fields.JSONField(null=True, description="响应体")
    request_params = fields.JSONField(null=True, description="请求参数")
    process_time = fields.FloatField(description="处理时间(ms)")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")

    # GeoIP信息
    country = fields.CharField(max_length=100, null=True, description="国家")
    city = fields.CharField(max_length=100, null=True, description="城市")
    latitude = fields.FloatField(null=True, description="纬度")
    longitude = fields.FloatField(null=True, description="经度")
    timezone = fields.CharField(max_length=50, null=True, description="时区")

    class Meta:
        table = "access_logs"
        ordering = ["-created_at"]
